#ifndef LIVESTATUSVIEW_H
#define LIVESTATUSVIEW_H

#include "libs/core/model/modeltype.h"
#include "liverecordertype.h"
#include <QTimer>
#include <QWidget>

QT_BEGIN_NAMESPACE
class QWebEngineProfile;
QT_END_NAMESPACE

class WebPage;
class WebView;

class LiveStatusView : public QWidget
{
    Q_OBJECT
public:
    LiveStatusView(const QString& name, QWidget* parent = nullptr);
    LiveStatusView(const QString& name, int interval, QWidget* parent = nullptr);
    ~LiveStatusView();

    bool captchaShown() const { return captcha_shown_; }
    bool passedCaptcha() const { return passed_captcha_; }
    int platform() const { return platform_; }
    int presenter() const { return presenter_; }
    bool handled() const { return handled_; }
    void getLiveStatus(int presenter, int platform, const QString& presenter_platform_id,
                       int timeout, const LiveHandler& handler);
    void unload();

Q_SIGNALS:
    void captchaStateChanged(bool passed);

private:
    QString setLiveInfo(const QString& args, const QString& success_callback,
                        const QString& failure_callback, const QString& sender_id,
                        QWidget* sender_view);
    QString setLiveStatus(const QString& args, const QString& success_callback,
                          const QString& failure_callback, const QString& sender_id,
                          QWidget* sender_view);
    QString setCaptcha(const QString& args, const QString& success_callback,
                       const QString& failure_callback, const QString& sender_id,
                       QWidget* sender_view);

    const QString name_;
    QWebEngineProfile* profile_;
    WebPage* page_;
    WebView* web_view_;
    QTimer* timer_;
    int interval_ = 0;
    bool captcha_shown_ = false;
    bool passed_captcha_ = false;
    int platform_;
    int presenter_ = 0;
    bool handled_ = true;
    LiveHandler handler_;
};

#endif // LIVESTATUSVIEW_H
